package main

import (
	"log"
	"math/rand"
	"net/http"

	"time"

	"runtime"

	"awfan.cn/implement"

	//	"awfan.cn/static"
	"awfan.cn/utils"

	"gopkg.in/mgo.v2"
)

func main() {
	rand.Seed(time.Now().UTC().UnixNano())

	log.Println("#go version:" + runtime.Version())

	session, err := mgo.Dial("127.0.0.1")

	if err != nil {
		log.Println("#dial error: " + err.Error())
		return
	}

	binfo, _ := session.BuildInfo()

	log.Println("#db version:" + binfo.Version)

	session.Close()

	http.HandleFunc("favicon.ico", func(w http.ResponseWriter, req *http.Request) {
		http.ServeFile(w, req, "html/favicon.ico")
	})

	//http.Handle("/js/", http.FileServer(http.Dir("static")))
	//http.Handle("/css/", http.FileServer(http.Dir("static")))
	//http.Handle("/html", http.FileServer(http.Dir("html")))
	http.Handle("/", http.FileServer(http.Dir("html")))

	http.HandleFunc(utils.API_ROUTES+"/", implement.Union)

	http.HandleFunc(utils.API_ROUTES+"/ws/", implement.Keep)

	log.Fatal("ListenAndServe:", http.ListenAndServe(":8080", nil))
}
